class SearchController < ApplicationController
	def index
		if request.get?
			@items = Item.where("UPPER(title) LIKE UPPER(?)", "%#{params[:title]}%").limit(2)
			@nbpage = Item.all().count() / 2
		end
	end
	
	def ajax_research
		if request.get?
			@page = params[:page]
			if @page == 'Search'
				@items = Item.where("UPPER(title) LIKE UPPER(?)", "%#{params[:title]}%").limit(2).offset(0)
			else
				@min = Integer(@page)*2 - 2
				@items = Item.where("UPPER(title) LIKE UPPER(:title)", {:title => "%#{params[:title]}%"}).limit(2).offset(@min)
			end
			respond_to do |format|
				format.html { render 'ajax_research', :layout => false }
			end
		end
	end
end
